clear all
use "C:\Users\sagomm\polybox\Shared\Circular Economy\w7_w8_subgroups_stata.dta"
destring, replace

******Install necesarry user-written commands
do "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\Scripts\functions\function_conjoint.do"
do "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\Scripts\functions\function_addplot.do"

****************************************************************************

*Interaction: Environmental attitudes and CC Characteristics

****************************************************************************
** Standard Conjoint **
qui reg choice i.Price_recoded i.Functional_duration_recoded i.env_impacts_recoded i.Energy_efficiency_recoded i.Recyclability_recoded i.Repairability_recoded, cluster(PubId)

egen envatt_sd = std(env_attitudes_mean)
************ EA & Price *******
loc ylab 0.35(.1).65

//Price
qui reg choice i.Price_recoded##c.envatt_sd ///
				i.Functional_duration_recoded##c.envatt_sd ///
				 i.env_impacts_recoded##c.envatt_sd ///
				 i.Energy_efficiency_recoded##c.envatt_sd ///
				 i.Recyclability_recoded##c.envatt_sd ///
				 i.Repairability_recoded, cluster(PubId)
eststo int_lr

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) Price_recoded=(1(1)4)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Price", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend(order(1 "very low" 2 "low" 3 "high" 4 "very high") ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt_att1, replace) 
	
//Functional duration
loc ylab 0.35(.1).65
qui reg choice i.Price_recoded##c.envatt_sd ///
				i.Functional_duration_recoded##c.envatt_sd ///
				 i.env_impacts_recoded##c.envatt_sd ///
				 i.Energy_efficiency_recoded##c.envatt_sd ///
				 i.Recyclability_recoded##c.envatt_sd ///
				 i.Repairability_recoded, cluster(PubId)
eststo int_lr

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) Functional_duration_recoded=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Functional duration", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend(order(1 "short" 2 "medium" 3 "long") ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt_att2, replace) 
	
//Environmental impact
loc ylab 0.35(.1).65
qui reg choice i.Price_recoded##c.envatt_sd ///
				i.Functional_duration_recoded##c.envatt_sd ///
				 i.env_impacts_recoded##c.envatt_sd ///
				 i.Energy_efficiency_recoded##c.envatt_sd ///
				 i.Recyclability_recoded##c.envatt_sd ///
				 i.Repairability_recoded, cluster(PubId)
eststo int_lr

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) env_impacts_recoded=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Environmental impact", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend(order(1 "very low" 2 "medium" 3 "very high") ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt_att3, replace) 
	
//Energy efficiency
loc ylab 0.35(.1).65
qui reg choice i.Price_recoded##c.envatt_sd ///
				i.Functional_duration_recoded##c.envatt_sd ///
				 i.env_impacts_recoded##c.envatt_sd ///
				 i.Energy_efficiency_recoded##c.envatt_sd ///
				 i.Recyclability_recoded##c.envatt_sd ///
				 i.Repairability_recoded, cluster(PubId)
eststo int_lr

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) Energy_efficiency_recoded=(1(1)4)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Energy efficiency", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend(order(1 "very low" 2 "low" 3 "medium" 4 "high") ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt_att4, replace) 
	
	
//Recyclability
loc ylab 0.35(.1).65
qui reg choice i.Price_recoded##c.envatt_sd ///
				i.Functional_duration_recoded##c.envatt_sd ///
				 i.env_impacts_recoded##c.envatt_sd ///
				 i.Energy_efficiency_recoded##c.envatt_sd ///
				 i.Recyclability_recoded##c.envatt_sd ///
				 i.Repairability_recoded, cluster(PubId)
eststo int_lr

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) Recyclability_recoded=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Recyclability", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("Pr(Choice)")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend(order(1 "poor" 2 "limited" 3 "good") ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt_att5, replace) 
	
//Repairability
loc ylab 0.35(.1).65
qui reg choice i.Price_recoded##c.envatt_sd ///
				i.Functional_duration_recoded##c.envatt_sd ///
				 i.env_impacts_recoded##c.envatt_sd ///
				 i.Energy_efficiency_recoded##c.envatt_sd ///
				 i.Recyclability_recoded##c.envatt_sd ///
				 i.Repairability_recoded, cluster(PubId)
eststo int_lr

est rest int_lr
qui margins, at(envatt_sd=(-2(1)2) Repairability_recoded=(1(1)3)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Repairability", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	ytitle("")  ///
	ylab("`ylab'",format(%3.2f)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labsize(small)) ///
	xti("") ///
	legend(order(1 "poor" 2 "limited" 3 "good") ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	ylabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(envatt_att6, replace) 
	
gr combine ///
	envatt_att4 ///
	envatt_att1 ///
	envatt_att2 ///
	envatt_att3 ///
	envatt_att5 ///
	envatt_att6, ///
	col (2) ///
	note("",  ///
	s(tiny) pos(7)) ///
	graphregion(color(white)) ///
	name(envatt_all, replace)

graph di, ysize(33) xsize(24)

//Save Figure 
gr export "C:\Users\sagomm\polybox\Shared\Circular Economy\Stata_Plots\Fig4_envatt_interaction.png", as(png) ///
	name("envatt_all") replace	

graph export "C:\Users\sagomm\polybox\Shared\Circular Economy\Stata_Plots\Fig4_envatt_interaction.pdf", as(pdf) name("envatt_all") replace

